package com.zxq.web.channel.device;

import com.zxq.exchange.model.ExchangeDTO;
import com.zxq.web.channel.SynchronismMessage;
import com.zxq.web.dto.PlatformCmdDTO;
import com.zxq.web.httpclient.HttpUtils;
import com.zxq.web.service.impl.ITransformServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service
public class DeviceMessageServiceImpl implements IDeviceMessage {

    /**
     * http客户端操作，请求
     */
    @Autowired
    HttpUtils httpUtils;

    /**
     * 翻译的操作
     */
    @Autowired
    ITransformServiceImpl transformService;

    /**
     * 同步消息对象
     */
    SynchronismMessage synchronismMessage;


    static DeviceMessageServiceImpl instance = null ;

    public static DeviceMessageServiceImpl getInstance() {
        return instance;
    }


    @PostConstruct
    public void init() {
        instance = this;
    }



    @Override
    public void deviceReport(ExchangeDTO exchangeDTO, String reportUrl, String token) {
        PlatformCmdDTO platformCmdDTO = transformService.devTransform(exchangeDTO);
        httpUtils.doReport(platformCmdDTO,reportUrl,token);
    }

    @Override
    public void deviceResult(ExchangeDTO exchangeDTO) {
        PlatformCmdDTO platformCmdDTO = transformService.devTransform(exchangeDTO);
        synchronismMessage.notifyPlatformMessage(platformCmdDTO.getDevId(),platformCmdDTO.getCmdId(),platformCmdDTO);
    }


}
